package com.loan.psychicloan.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;

import com.loan.psychicloan.R;

/**
 * Created by watilion on 2018/1/3 0003.
 */

public class WebViewActivity extends AppCompatActivity {


    private ProgressBar mProgressBar;

    private Intent dataIntent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_webview);


        dataIntent = getIntent();

        initview();
    }

    @SuppressLint("SetJavaScriptEnabled")
    private void initview() {

        mProgressBar = findViewById(R.id.webview_activity_progressbar);
        WebView mWebView = findViewById(R.id.webviewactivity_webview);
        //支持js
        mWebView.getSettings().setJavaScriptEnabled(true);
        //支持缩放
        mWebView.getSettings().setSupportZoom(true);
        mWebView.getSettings().setBuiltInZoomControls(true);
        //接口回调
        mWebView.setWebChromeClient(new WebViewClient());
        //加载页面

        mWebView.loadUrl(dataIntent.getStringExtra("loanurl"));
        //本地显示
        mWebView.setWebViewClient(new android.webkit.WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                //我接受这个信息
                return true;
            }
        });
    }

    public class WebViewClient extends WebChromeClient{
        //进度变化监听
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            mProgressBar.setProgress(newProgress);
            if (newProgress == 100) {
                mProgressBar.setVisibility(View.GONE);
            }
            super.onProgressChanged(view, newProgress);

        }
    }
}
